home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / shell / shell.swf / scripts / DefineSprite_107 / frame_1 / DoAction.as
Text File  |  2004-07-06  |  6KB  |  265 lines

  1. function prepare(str)
  2. {
  3.    clearUp();
  4.    if(str == "")
  5.    {
  6.       return undefined;
  7.    }
  8.    numCurrent = -1;
  9.    strPlaylistID = str;
  10.    enabled = true;
  11.    var xmlAdverts = new XML();
  12.    xmlAdverts.ignoreWhite = true;
  13.    xmlAdverts.onLoad = function()
  14.    {
  15.       xmlPlaylist = xmlAdverts.byPath("adverts/@" + strPlaylistID);
  16.       delete xmlAdverts;
  17.       loadAdvert();
  18.    };
  19.    xmlAdverts.load(ADVERTS_DATA);
  20. }
  21. function start()
  22. {
  23.    next();
  24. }
  25. function clearUp()
  26. {
  27.    mc_file.unloadMovie();
  28.    delete mc_file.onEnterFrame;
  29.    clearInterval(numWaitID);
  30.    enabled = false;
  31.    expandable = false;
  32.    delete strPlaylistID;
  33.    delete xmlPlaylist;
  34. }
  35. function onClicked()
  36. {
  37.    if(Tardis.Childlock.active == true)
  38.    {
  39.       return undefined;
  40.    }
  41.    if(ndCurrent.attributes.category == "web")
  42.    {
  43.       var strWebURL = ndCurrent.attributes.url;
  44.       if(Tardis.PLAY_MODE == "browser")
  45.       {
  46.          getURL(strWebURL,"");
  47.          return undefined;
  48.       }
  49.       var strLog = xmlPlaylist.attributes.index + "." + numCurrent;
  50.       Tardis.UsageData.addWebAdvertEntry(strLog);
  51.       Tardis.webPageOpen(strWebURL);
  52.    }
  53.    else
  54.    {
  55.       if(Tardis.PLAY_MODE == "browser")
  56.       {
  57.          return undefined;
  58.       }
  59.       var numAds = xmlPlaylist.childNodes.length;
  60.       var arrAdList = new Array();
  61.       trace("numAds: " + numAds);
  62.       trace("numCurrent: " + numCurrent);
  63.       var i = 0;
  64.       while(i < numAds)
  65.       {
  66.          if(Number(xmlPlaylist.childNodes[i].attributes.playlistId) == numCurrent + 1)
  67.          {
  68.             arrAdList.push(xmlPlaylist.childNodes[i]);
  69.          }
  70.          i++;
  71.       }
  72.       var obj = createOverlayObj(ndCurrent,arrAdList);
  73.       Tardis.OverlayController.addAdvertOverlay(obj,true);
  74.       var strLog = xmlPlaylist.attributes.index + "." + numCurrent;
  75.       var strType = "advert";
  76.       Tardis.UsageData.addAdvertEntry(strLog,strType);
  77.    }
  78. }
  79. function createOverlayObj(xmlNode, arrAdList)
  80. {
  81.    var obj = {filename:xmlNode.attributes.overlay,strType:xmlNode.attributes.category,showDelay:xmlNode.attributes.showDelay,allowNeverSee:0,isFullscreen:true,disableLevel:2,closeBut:"advert",arrXmlAdList:arrAdList};
  82.    return obj;
  83. }
  84. function onRolledOver()
  85. {
  86.    this._parent.expandAd();
  87. }
  88. function onRolledOut()
  89. {
  90.    this._parent.collapseAd();
  91. }
  92. function onAnimationfinished()
  93. {
  94.    fadeDown();
  95. }
  96. function interrupt()
  97. {
  98.    if(enabled == false)
  99.    {
  100.       error("adverts : interrupt : adverts not enabled");
  101.    }
  102.    var strWaitMode = ndCurrent.attributes.wait;
  103.    switch(strWaitMode)
  104.    {
  105.       case "swfend":
  106.          mc_file.onEnterFrame = null;
  107.          mc_file.stop();
  108.          break;
  109.       case "static":
  110.       case "script":
  111.          break;
  112.       default:
  113.          if(parseInt(strWaitMode) == strWaitMode)
  114.          {
  115.             clearInterval(numWaitID);
  116.             break;
  117.          }
  118.    }
  119. }
  120. function resume()
  121. {
  122.    if(enabled == false)
  123.    {
  124.       error("adverts : resume : adverts not enabled");
  125.    }
  126.    startWait();
  127. }
  128. function fadeDown()
  129. {
  130.    clearInterval(numWaitID);
  131.    if(enabled == false)
  132.    {
  133.       return undefined;
  134.    }
  135.    mc_file.onEnterFrame = function()
  136.    {
  137.       with(this)
  138.       {
  139.          _alpha -= 10;
  140.          if(_alpha <= 0)
  141.          {
  142.             onEnterFrame = null;
  143.             _parent.next();
  144.          }
  145.       }
  146.    };
  147. }
  148. function fadeUp()
  149. {
  150.    trace("fade up");
  151.    with(this)
  152.    {
  153.       _alpha += 10;
  154.       if(_alpha >= 100)
  155.       {
  156.          trace("alpha is 100");
  157.          _alpha = 100;
  158.          trace("_parent.expandable = " + _parent.expandable);
  159.          trace("typeof(_parent.expandable ): " + typeof _parent.expandable);
  160.          if(_parent.expandable == "true")
  161.          {
  162.             gotoAndStop(2);
  163.             trace("clip faded in - now play it");
  164.             trace("this: " + this);
  165.             content_mc.play();
  166.          }
  167.          else
  168.          {
  169.             play();
  170.          }
  171.          onEnterFrame = null;
  172.          _parent.enableButton();
  173.          _parent.startWait();
  174.       }
  175.    }
  176. }
  177. function loadAdvert()
  178. {
  179.    numCurrent = 0;
  180.    if(numCurrent == xmlPlaylist.childNodes.length)
  181.    {
  182.       numCurrent = 0;
  183.    }
  184.    ndCurrent = xmlPlaylist.byIndex(numCurrent);
  185.    mc_file.removeMovieClip();
  186.    this.createEmptyMovieClip("mc_file",++depth);
  187.    mc_file._alpha = 0;
  188.    var f = function()
  189.    {
  190.       trace("advert loaded");
  191.       this.onLoad = null;
  192.       this._parent.expandable = this._parent.ndCurrent.attributes.expandable;
  193.       this.onEnterFrame = this._parent.fadeUp;
  194.    };
  195.    mc_file = _parent.adverts.mc_file;
  196.    mc_file.onLoad = f;
  197.    mc_file.loadMovie(ADVERT_PATH + ndCurrent.attributes.file);
  198. }
  199. function enableButton()
  200. {
  201.    if(ndCurrent.attributes.expandable == "true")
  202.    {
  203.       mc_file.mask_mc.onRelease = function()
  204.       {
  205.          onClicked();
  206.       };
  207.       mc_file.mask_mc.onRollOver = onRolledOver;
  208.       mc_file.mask_mc.onRollOut = onRolledOut;
  209.       expandable = true;
  210.    }
  211.    else
  212.    {
  213.       mc_file.onRelease = function()
  214.       {
  215.          onClicked();
  216.       };
  217.    }
  218. }
  219. function startWait()
  220. {
  221.    var strWaitMode = ndCurrent.attributes.wait;
  222.    switch(strWaitMode)
  223.    {
  224.       case "swfend":
  225.          if(expandable == false)
  226.          {
  227.             mc_file.play();
  228.          }
  229.          mc_file.onEnterFrame = function()
  230.          {
  231.             with(this)
  232.             {
  233.                if(_currentframe == _totalframes)
  234.                {
  235.                   stop();
  236.                   onEnterFrame = null;
  237.                   _parent.fadeDown();
  238.                }
  239.             }
  240.          };
  241.          break;
  242.       case "static":
  243.       case "script":
  244.          break;
  245.       default:
  246.          if(parseInt(strWaitMode) == strWaitMode)
  247.          {
  248.             numWaitID = setInterval(this,"fadeDown",strWaitMode * 1000);
  249.             break;
  250.          }
  251.    }
  252. }
  253. stop();
  254. ADVERT_PATH = Tardis.ASSETS_FOLDER + "adverts/";
  255. ADVERTS_DATA = Tardis.ASSETS_FOLDER + "xml/adverts.xml";
  256. PATHS = [["adverts/overlays/vwgolf"],["adverts/overlays/test2"],[],[],[],[],[],[]];
  257. var numWaitID;
  258. var numCurrent;
  259. var enabled = false;
  260. var expandable = false;
  261. this.onUnload = function()
  262. {
  263.    clearUp();
  264. };
  265.